"""
	Developerd by Andrea Stagi <stagi.andrea@gmail.com>
	TwittLine - the client twitter on your terminal
	Copyright (C) 2010 Andrea Stagi

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import os
import getpass
from tinyurl import *
import string

def createHelp(comlist):

	retcmd=""

	for cmd in comlist:
		retcmd=retcmd + "[" + cmd + "]"

	return retcmd

def tinyPass(command):

	cmds=command.split()
	retcmd=""
	newcmd=""
	i=0
	
	for cmd in cmds:
		
		if(cmd[0:4]=="$ty="):
			newcmd=cmd[4:len(cmd)]

			if(newcmd[0:7]!="http://"):
				newcmd="http://" + newcmd			
			cmds[i]=create_one(newcmd)
		else:
			i+=1
			continue

	for cmd in cmds:
		retcmd=retcmd + " " + cmd

	return retcmd
			

def stringToInt(string):

	if(string==""):
		return -1;	

	id=ord(string[0])-48
	if(len(string)>1):
		id=id*10
		id=id+(ord(string[1])-48)

	return id

def getchar():

	try:
		import sys, tty, termios

		fd = sys.stdin.fileno()
		old_settings = termios.tcgetattr(fd)

		try:
			tty.setraw(sys.stdin.fileno())
			ch = sys.stdin.read(1)
		
		finally:
			termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)

		return ch
		
	except ImportError:
	
		import msvcrt
        return msvcrt.getch()

def getPassword():

	password=""
	ch=''

	while(1):

		ch=getchar()
		if(ord(ch)==13):
			return password
		password+=ch
		print "*",

	return password

def clearScreen():

	if(os.name=="posix"):
		os.system("reset")
		os.system("clear")
	else:
		os.system("cls")
	
